<?php

namespace App\Api\V1\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Cache;

/**
 * 系统设置
 * Class SystemController
 * @package App\Api\V1\Controllers
 */
class SystemController extends CommonController
{
    public function __construct()
    {
        parent::__construct();
        // 获取用户基本信息
        $this->getUserInfo(false);
    }

    /**
     * 版本更新
     * @return array
     */
    public function index()
    {
        // 获取请求源
        $client_source = IT('ClientSource',1);
        if ($client_source == 1) {// 安卓
            $where = array(
                ['key','=','apk_version'],
                ['status','=',1]
            );
        } else if ($client_source == 2) {// IOS
            $where = array(
                ['key','=','ios_version'],
                ['status','=',1]
            );
        } else {// WEB
            return json_success('ok',[], 10000);
        }
        // 获取请求源最新版本URL
        $version = D('config')->where($where)->first(['value','ask_value','make_content','download_links']);
        $return = array(
            'url' =>$version->download_links ,
            'version' => $version->value,
            'ask_version' => $version->ask_value,
            'make_content' => $version->make_content,
        );
        return json_success('ok', $return, 10000);
    }
    /**
     * 清除缓存
     * 注意：请将需要清除的缓存添加一份到该方法
     * @return array
     */
    public function clearCache()
    {
        Cache::forget('key');
        return json_success('缓存清除成功', [], 10112);
    }
}